import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
//        Scanner in = new Scanner(System.in);
//        float a = in.nextFloat();
//        String b = in.next();
//        int money = count_money(a,b);
//        System.out.print(money);
/*
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] arr = new int[n];
        for(int i = 0; i < n; i++) {
            arr[i] = in.nextInt();
        }
        int min_money = cost_min(arr);
        System.out.println(min_money);*/


        Scanner in = new Scanner(System.in);
        //代表strs的长度
        int n = in.nextInt();
        //代表strs中第一个字符串
        String one = in.nextLine();
        //代表strs第二个字符串
        String two = in.nextLine();
        String[] s = new String[n];
        for(int i = 0; i < n; i++) {
            s[i] = in.nextLine();
        }
        int distance = sort_distance(one,two,s);
        System.out.println(distance);

    }
    public static int cost_min(int[] arr) {
        //定义一个dp数组，表示当前格子最小花费
        int n = arr.length;
        int[] dp = new int[n+1];
        //定义一个dp数组，表示当前格子最小花费
        if(n == 1) {
            return arr[0];
        }
        if(n == 2) {
            return Integer.min(arr[1],arr[0]);
        }
        dp[0] = 0;
        dp[1] = 0;
        int min_money = Integer.MAX_VALUE;;
        for(int i = 2; i <= n; i++) {
            //可能由前一个位置跳一步，或者前两个位置跳两步(支付一次费用)
            dp[i] = Integer.min(dp[i-1]+arr[i-1],dp[i-2] + arr[i-2]);
        }
        return dp[n];
    }

    public static int count_money(float a,String b) {
        float money = 0;
        if(a > 1) {
            a = a - 1;
            money = 20;
            if(a % 1 > 0) {
                money = money + (int)a + 1;
            }else{
                money = money + a*1;
            }
        }else{
            money = 20;
        }
        if(b.charAt(0) == 'y') {
            money += 5;
        }
        return (int)money;
    }

    private static int sort_distance(String a,String b,String[] s) {
        if(a == null) {
            return -1;
        }
        if(b == null) {
            return -1;
        }
        //首先判断是否包含
        Map<Integer,String> map = new HashMap<Integer,String>();
        for(int i = 0; i < s.length; i++) {
            if(!map.containsKey(s[i])) {
                map.put(i,s[i]);
            }
        }
        if(!map.containsValue(a)) {
            return -1;
        }
        if(!map.containsValue(b)) {
            return -1;
        }
        //包含判断距离
        return 0;
    }
}
